package org.alis.smallcc.designpatterns.behavior.state;

import org.alis.smallcc.designpatterns.behavior.memento.Originator;
import org.apache.commons.lang3.StringUtils;

/**
 * 状态模式
 * 
 * @author luochuan
 */
public interface State {
	
	String currentState();
	
	boolean canChanage(Originator context);
	
	default void doAction(Originator context) {
		context.setState(this);
	}
	
	default void action(Originator originator) {
		System.out.println(String.format("%s处于%s", originator.getOriginator(),currentState()));
		if(StringUtils.equals(originator.getState(), currentState())) {
			System.out.println(String.format("当前状态%s与%s的状态%s相同", originator.getState(),originator.getOriginator(),currentState()));
			return;
		}
		if(canChanage(originator)) {
			this.doAction(originator);
		}
		
	}
}
